import { baseURL } from '../axios.config';
import { get, post } from '/@/api/http'
const serverContextPath = '/example-server'
export interface ProcessVo {
	processInstanceId: string;
	processDefId: string;
	processDefKey: string;
	approveNo: string;
	processDefName: string;
	briefReport: string;
	startUserId: string;
	startUserName: string;
	startTime: Date;
	endTime: Date;
	assigneeName: string;
	businessKey: string;
	businessDesignerId: string;
	businessDesignerCode: string;
	processState: string;
	deleteReason: string;
}
export interface TaskVo{
	taskId: string;
	taskKey: string;
	approveNo: string;
	taskName: string;
	processInstanceId: string;
	processDefId: string;
	processDefKey: string;
	processDefName: string;
	briefReport: string;
	formRefKey: string;
	startUserId: string;
	startUserName: string;
	startTime: string;
	assignee: string;
	assigneeName: string;
	businessKey: string;
	businessDesignerId: string;
	businessDesignerCode: string;
	description: string;
	approveAdvice: string;
	endTime: string;
	taskState: string;
	durationInSecond: number;
}
/**
 * 流程参数
 */
export interface TaskParam{
	taskId: string;
	processId: string;
	defKey: string;
	businessKey: string;
	tenantId: string;
	description: string;
	userId: string;
	approveAdvice: string;
	approveUserId: string;
	briefReport: string;
	skipFirstNode: string;
	processVariables: object;
	taskVariables: object;
	formProperties: object;
	businessDesignerId: string;
	businessDesignerCode: string;
	owner: string;
	authCategory: string;
}
export const workflowApi = {
	/**
	 * 查询流程设计模型
	 * @param data 
	 * @returns 
	 */
	getProcessDefinitionList: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/model/list',
			data: data,
		})
	},
	/**
	 * 上传流程文件
	 * @param {*} formData 
	 */
	uploadModelFile: (formData: any) => {
		return post({
			url: serverContextPath + '/workflow/model/uploadModelFile',
			data: formData,
			headers: { 'Content-Type': 'multipart/form-data; charset=utf-8' },
		})
	},
	/**
	 * 根据ID删除流程设计数据
	 */
	modelDeleteById: (id: any) => {
		return get({
			url: serverContextPath + '/workflow/model/delete/' + id,
		})
	},
	/**
	 * 下载流程文件
	 * @param {*} id 
	 */
	exportXml: (deploymentId: string) => {
		let a = document.createElement('a')
		a.href = baseURL + serverContextPath + '/workflow/model/export/' + deploymentId
		a.click()
	},
	/**
	 * 发布流程
	 */
	modelDeploy: (id: any) => {
		return get({
			url: serverContextPath + '/workflow/model/deploy/' + id,
		})
	},
	/**
	 * 根据部署id获取流程定义
	 * @param {} deploymentId 
	 */
	getProcessDefinition: (deploymentId: string) => {
		return get({
			url: serverContextPath + '/workflow/model/getProcessDefinition/' + deploymentId,
		})
	},
	/**
	 * 
	 * @param data 
	 * @returns 
	 */
	getModelDeployHisList: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/model/getModelDeployHisList',
			data: data,
		})
	},
	getResourceByDefId: (defId: string)=> {
		return get({
			url: serverContextPath + '/workflow/model/getResourceByDefId/' + defId,
		})
	},
	/**
	 * 
	 * @param data{id, key, name, xml} 保存流程设计
	 * @returns 
	 */
	saveProcessDefinition: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/model/saveProcessDefinition',
			data: data
		})
	},
	/**
	 * 根据流程实例ID查询流程图及高亮
	 * @param processId 
	 * @returns 
	 */
	 getResourceAndStateByProcessId: (processId: string)=> {
		return get({
			url: serverContextPath + '/workflow/process/getResourceAndStateByProcessId/' + processId,
		})
	},
	/**
	 * 分页查询待办任务
	 * @param data 
	 * @returns 
	 */
	getTodoTaskListPage: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/process/todoList',
			data: data
		})
	},
	/**
	 * 分页查询我发起的流程
	 * @param data 
	 * @returns 
	 */
	getCreateListPage: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/process/createList',
			data: data
		})
	},
	/**
	 * 分页查询我参与的流程
	 * @param data 查询条件
	 * @returns 
	 */
	 getPartakeListPage: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/process/partakeList',
			data: data
		})
	},
	/**
	 * 检出待办任务
	 * @param taskId 任务ID
	 * @param sign 0、1检出、检入
	 * @returns 
	 */
	doClaimTask: (taskId: string, sign: string) => {
		return get({
			url: serverContextPath + '/workflow/process/doClaimTask/' + taskId + '/' + sign
		})
	},
	/**
	 * 查询流程审批历史记录
	 * @param processId 流程实例ID
	 * @returns 
	 */
	getHisTaskByProcessId: (processId: string) => {
		return get<TaskVo[]>({
			url: serverContextPath + '/workflow/process/getHisTaskByProcessId/' + processId
		})
	},
	/**
	 * 获取可退回节点
	 * @param taskId 任务ID
	 * @returns 
	 */
	getRetractNodeByTaskId: (taskId: string) => {
		return get<TaskVo[]>({
			url: serverContextPath + '/workflow/process/getRetractNodeByTaskId/' + taskId
		})
	},
	/**
	 * 流程退回
	 * @param data 
	 * @returns 
	 */
	submitRetract: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/process/submitRetract',
			data: data
		})
	},
	/**
	 * 终止流程
	 * @param processId 流程实例ID
	 * @param stopReason 终止原因
	 * @returns 
	 */
	deleteProcess: (processId: string, stopReason: string) => {
		return post({
			url: serverContextPath + '/workflow/process/deleteProcess',
			data:{
				processId: processId,
				stopReason: stopReason,
			}
		})
	},
	/**
	 * 发起人撤回流程
	 * @param processId 流程实例ID
	 * @returns 
	 */
	recallTaskByStarter(processId: string) {
		return get({
			url: serverContextPath + '/workflow/process/recallTaskByStarter/' + processId,
		})
	},
	/**
	 * 获取可撤回节点（流程中我参与过的节点）
	 * @param processId 流程实例ID
	 * @returns 
	 */
	getCanRecallTask(processId: string) {
		return get<TaskVo[]>({
			url: serverContextPath + '/workflow/process/getCanRecallTask/' + processId,
		})
	},
	/**
	 * 选节点撤回
	 * @param data 参数 
	 * @returns 
	 */
	recallTaskAny(data: any) {
		return post({
			url: serverContextPath + '/workflow/process/recallTaskAny',
			data: data,
		})
	},
	/**
	 * 流程管理分页查询
	 * @param data 
	 * @returns 
	 */
	queryProcessPage(data: any) {
		return post({
			url: serverContextPath + '/workflow/process/queryProcessPage',
			data: data,
		})
	},
	/**
	 * 分页查询审批人找人策略
	 * @param data {
				page: pagination.page,
				pageSize: pagination.pageSize,
				param: {...},
			}
		* @returns
		*/
	queryWfStrategyListPage: (data: any) => {
		return post({
			url: serverContextPath + '/workflow/wfStrategy/page',
			data: data,
		})
	},
	/**
	 * 新增审批人找人策略
	 * @param dataForm 参数
	 * @returns
	 */
	saveWfStrategyInfo: (dataForm: any) => {
		return post({
			url: serverContextPath + '/workflow/wfStrategy/save',
			data: dataForm,
		})
	},
	/**
	 * 修改审批人找人策略
	 * @param dataForm 参数
	 * @returns
	 */
	updateWfStrategyInfo: (dataForm: any) => {
		return post({
			url: serverContextPath + '/workflow/wfStrategy/update',
			data: dataForm,
		})
	},

	/**
	 * 删除审批人找人策略
	 * @param id 主键
	 * @returns
	 */
	deleteWfStrategyInfo: (id: string) => {
		return post({
			url: serverContextPath + '/workflow/wfStrategy/remove/' + id,
		})
	},
	/**
	 * 查询策略{key，value}
	 * @returns 
	 */
	getWfStrategyKeyValue: () => {
		return get({
			url: serverContextPath + '/workflow/wfStrategy/getWfStrategyKeyValue'
		})
	},
	transferProcess: (taskId: string, userId: string) => {
		return get({
			url: serverContextPath + '/workflow/process/transferProcess/' + taskId + '/' + userId
		})
	}
}